/*********************************************************************************
 *FileName:  wdg.c
 *Author:    ChenJiehong
 *Version:   V1.0
 *Date:      2024-03-19
 ****************************************Includes***********************************/
#include "wdg.h"

/***************************************Variables***********************************/

/***************************************Functions***********************************/

void WDG_Init(void)
{

	WWDG_Disable();
	DWDG_Disable();
	
	/* 35K/128 ~= 273.4Hz 255个计数值0.93s*/
	WWDG_SetPrescaler(WWDG_Prescaler_128); 
	WWDG_SetWindowValue(WWDG_WINDOW_KEY);	/* 设置为0xFF,只使用计数到0 复位*/
	WWDG_Enable();
	

	DWDG_SetPrescaler(DWDG_Prescaler_512);	/* 32MHz/512 = 62.5KHz */
	DWDG_SetReloadValue(6250);				/* 100ms */
	DWDG_Enable();
	
}

void WDG_Manager(void)
{
	/* Feeding Watch dog */
	WWDG_SetCounter(WWDG_RELOAD_KEY);
	DWDG_SetReloadKey();
}

void WDG_DInit(void)
{
	WWDG_Disable();
	DWDG_Disable();
}

//void WDG_Init(void)
//{
//	WWDG_Disable();
//	
//	WWDG_SetPrescaler(WWDG_Prescaler_128); /* 35K/128 ~= 273.4Hz */
//	
//	/* 时间 = (WWDG_RELOAD_KEY-WWDG_WINDOW_KEY)/(AUX/Pre) */
//	/* 时间 = (0xFF-0x60)/273.4Hz = 0.581s */
//	WWDG_SetWindowValue(WWDG_WINDOW_KEY);	
//	
//	WWDG_Enable();
//	WDG_Manager();
//}

//void WDG_DInit(void)
//{
//	WWDG_Disable();
//}

//void WDG_Manager(void)
//{
//	WWDG_SetCounter(WWDG_RELOAD_KEY);
//}

/***************************************END OF FILE*********************************/
